﻿using nplJobsCommon.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Select
{
    public class SelectApplicationProcedure : DataAccessBase
    {
        public SelectApplicationProcedure()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectApplicationProcedure.ToString();
        }

        #region GetApplicationProcedure
        public List<ApplicationProcedure> GetApplicationProcedure()
        {
            DataBaseHelper dbHelper;
            DataSet dsApplicationProcedure;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsApplicationProcedure = dbHelper.Run(base.ConnectionString);
                return GetList(dsApplicationProcedure);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<ApplicationProcedure> GetList(DataSet dsApplicationProcedure)
        {
            List<ApplicationProcedure> applicationProcedures;
            try
            {
                applicationProcedures = (from n in dsApplicationProcedure.Tables[0].AsEnumerable()
                                  select new ApplicationProcedure
                                   {
                                       ID = n.Field<int>("ID"),
                                       Procedure = n.Field<string>("Procedure")
                                   }).ToList();

                return applicationProcedures;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
